﻿#region [ License information          ]
/* ************************************************************
 *
 * Copyright (c) Bjørn Bouet Smith, 2010, 2011
 *
 * This source code is subject to terms and conditions of 
 * Microsoft Public License (Ms-PL).
 * 
 * A copy of the license can be found in the license.txt
 * file at the root of this distribution. If you can not 
 * locate the License, please send an email to bjornsmith@gmail.com
 * 
 * By using this source code in any fashion, you are 
 * agreeing to be bound by the terms of the Microsoft 
 * Public License.
 *
 * You must not remove this notice, or any other, from this
 * software.
 *
 * ************************************************************/
#endregion

using System;
using Smith.AMC.Operations;

namespace Smith.AMC.Network
{
    /// <summary>
    /// Encapsulates the work being done on client sockets.
    /// i.e. retrieving a socket from the pool, sending commands, translating responses into proper responses for clients.
    /// </summary>
    public interface ISocketWorker : IDisposable
    {

        /// <summary>
        /// Begins an asynchronous operation against the memcached server.
        /// </summary>
        /// <typeparam name="T">Type of item to return from the socket operation</typeparam>
        /// <param name="operation">The operation to execute against the memcached server.</param>
        /// <param name="callback">The <see cref="System.AsyncCallback"/> delegate that is executed when the BeginSocketOperation operation completes</param>
        /// <param name="state">An object that contains any additional user-defined data.</param>
        /// <returns>
        /// An <see cref="System.IAsyncResult"/> that represents the asynchronous call.
        /// </returns>
        IAsyncResult BeginSocketOperation<T>(Operation operation, AsyncCallback callback, object state);

        /// <summary>
        /// Handles the end of the asynchronous socket operation
        /// </summary>
        /// <typeparam name="T">Type of item to return from the socket operation</typeparam>
        /// <param name="asyncResult">An <see cref="System.IAsyncResult"/> that represents the asynchronous call.</param>
        /// <returns>
        /// An operation response with the response of the memcached server.
        /// </returns>
        OperationResponse<T> EndSocketOperation<T>(IAsyncResult asyncResult);
    }
}
